(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:HomeCtrl
     * @description
     * # HomeCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('HomeCtrl', HomeCtrl);

    HomeCtrl.$inject = ['$scope', 'dataService', 'helper', '$timeout', '$interval', '$rootScope', '$state', 'cacheService', ];

    function HomeCtrl($scope, dataService, helper, $timeout, $interval, $rootScope, $state, cacheService) {
        $scope.indexAction = function() {
            //加载数据
            console.error("currentUser.", $scope.currentUser);
        }

        $scope.aa = function() {

            var cid = "pL3Xyt2zQEHoAlpBrdVSjNiCbP2U";
            // var cid = "pDF3iY9tv9zCGCj4jTXFOo1DxHdo";
            
            var data = {
                "content": { "card_id": cid },
                "method": "dhf.card.sign.get"
            };

            dataService.cardSignGet(data).then(function(php_data) {
                console.error("phpProxy 返回结果-->", php_data);
                // return false;
                if (php_data.errcode && php_data.errmsg) {
                    console.error("错误提示-->", php.errmsg);
                } else {
                    var cardExt = JSON.stringify({ "timestamp": php_data.timestamp, "signature": php_data.signature });
                    // var cardExt = '{"timestamp": 1418301401,"signature":"f6628bf94d8e56d56bfa6598e798d5bad54892e5"}'
                    console.error(php_data.signature);
                    console.error("cardExt", cardExt);
                    // addCard
                    wx.addCard({
                        cardList: [{
                            cardId: cid,
                            cardExt: cardExt
                        }],
                        success: function(res) {
                            console.error('领取卡券到卡包：', JSON.stringify(res));
                            console.error('领取卡券到卡包：', JSON.stringify(res.cardList));
                        },
                        cancel: function(res) {
                            // console.error("取消领取卡券：", JSON.stringify(res))
                        }
                    });
                }
            });


            return false;

            wx.addCard({
                cardList: [{
                    cardId: 'pDF3iY9tv9zCGCj4jTXFOo1DxHdo',
                    cardExt: '{"code": "", "openid": "", "timestamp": "1418301401", "signature":"f6628bf94d8e56d56bfa6598e798d5bad54892e5"}'
                }, {
                    cardId: 'pDF3iY9tv9zCGCj4jTXFOo1DxHdo',
                    cardExt: '{"code": "", "openid": "", "timestamp": "1418301401", "signature":"f6628bf94d8e56d56bfa6598e798d5bad54892e5"}'
                }],
                success: function(res) {
                    alert('宸叉坊鍔犲崱鍒革細' + JSON.stringify(res.cardList));
                },
                cancel: function(res) {
                    alert(JSON.stringify(res))
                }
            });
        }
    }
})();